package com.dp.tj;

import org.apache.log4j.Logger;
import org.quartz.CronTrigger;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

import com.dp.service.impl.QuartzJob_ClearServer;
import com.dp.service.impl.QuartzJob_PublishChannel;
import com.dp.util.InterUtil;



//import com.hs.portalv8.www.pub.SysProperty;

//import com.hs.portalv8.www.pub.SysProperty;
//import com.hurray.dreamcard.base.utils.BaseBean;
//import static com.hurray.dreamcard.base.utils.GetPropertyAndJNDI.getInstance;

public class JobScheduler
{
	//private static Logger log = com.hurray.dreamcard.base.utils.MyLoger.getLogger("Month_Scheduler");
	public static SchedulerFactory sf = null;
    public static Scheduler sched = null;
	public void createjob()
	{
		try
		{
			if(sched==null)
				{
					sf = new StdSchedulerFactory();
					sched = sf.getScheduler();
				}
			
			//String refreshtime=(String)new InitialContext().lookup("java:comp/env/refreshtime");
			/**/
			String jn="QuartzJob_PublishChannel";
			String group="jdg";
			String time="0 1/5 * * * ? *";
			
			
					
	            JobDetail job_creatfile=sched.getJobDetail(jn,group);
		        if(job_creatfile!=null)	sched.deleteJob(jn,group);
		        job_creatfile= new JobDetail(jn,group, QuartzJob_PublishChannel.class);
		        CronTrigger trigger_creatfile=new CronTrigger(jn,group); 		        
		        trigger_creatfile.setCronExpression(time); 
		        sched.scheduleJob(job_creatfile, trigger_creatfile);	
		        
		        
		        
//		        String d="30 "+(1+(int)(Math.random()*20))+" 5 * * ? *";//防止两台机器同时删除
//				String[] times={d,,"0 0/1 * * * ? *"};
		        
		        String cl="QuartzJob_ClearServer";
				   job_creatfile=sched.getJobDetail(cl,group);
			        if(job_creatfile!=null)	sched.deleteJob(cl,group);
			        job_creatfile= new JobDetail(cl,group, QuartzJob_ClearServer.class);
			        trigger_creatfile=new CronTrigger(cl,group); 		        
			        trigger_creatfile.setCronExpression("34 10 5 * * ? *"); 
			        sched.scheduleJob(job_creatfile, trigger_creatfile);
		        
		        
		       // sched.start();	
		        sched.startDelayed(10);
	       Logger.getLogger(this.getClass()).info("QuartzJob_CreateTimer "+InterUtil.rb.getString("src.starttimer"));
//	        sched.start();
		}
		catch(Exception ex)
		{
			ex.printStackTrace();			
		}
	}
}
